package com.yst.sqlbuilder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SQLExpGroup<L,R> implements ISQLExpressionGroup<L> {
    private final List<SQLExp<L,R>> expList=new ArrayList<>();
    private final LinkMode linkMode;

    @SafeVarargs
    public SQLExpGroup(LinkMode linkMode, SQLExp<L,R>...expressions){
        this.linkMode=linkMode;
        this.expList.addAll(Arrays.asList(expressions));
    }

    public static <L,R> SQLExpGroup<L,R> or(SQLExp<L,R>...expressions){
        return new SQLExpGroup(LinkMode.OR,expressions);
    }

    public static <L,R> SQLExpGroup<L,R> and(SQLExp<?,?>...expressions){
        return new SQLExpGroup(LinkMode.AND,expressions);
    }

    @Override
    public String generateExpression(GenerateParam param) {
        return ISQLExpressionGroup.super.generateExpression(param);
    }

    @Override
    public LinkMode getLinkMode() {
        return linkMode;
    }

    @Override
    public IExpression[] getExpressions() {
        return expList.toArray(new IExpression[0]);
    }

}
